var _util = require('util/util.js')
var vue = require('./../common/vue')
const { toHandlerKey } = require('vue');
const _other_service = require('service/other-service');

var user_content = new vue({
    el: "#user_content",
    //定义数据
    data: {
        userArray: [
            {
                username: "hsj",
                password: "123",
                phone: "123",
                sex: "男",
                age: "20",
                email: "123@qq.com",
                country: "日本",
                signature: "烂掉烂掉!",
                available: 1,
                picturesrc: "<image src=\"/image/user_picture/1.jpg\">"
            },
            {
                username: "shizukururu",
                password: "123",
                phone: "123",
                sex: "女",
                age: "20",
                email: "123@qq.com",
                country: "日本",
                signature: "天选国V",
                available: 1,
                picturesrc: "<image src=\"/image/user_picture/1.jpg\">"
            },
            {
                username: "丁真",
                password: "123",
                phone: "123",
                sex: "男",
                age: "20",
                email: "123@qq.com",
                country: "中国",
                signature: "首席鉴定师",
                available: 1,
                picturesrc: "<image src=\"/image/user_picture/1.jpg\">"
            }
        ],
        //搜索框关键字
        search_keywords : "",
        /*
            修改启用状态
            edit_username: 当前操作的用户名
            available: 是否启用
         */
        edit_username : "",
        available: "",
        /*
            分页查询参数 1!5!
         */
        pagesize: 5,
        pageid: 1,
    },
    methods: {
        //查询所有的用户(分页)
        search: function () {
            console.log(this.search_keywords)
            _other_service.getusersby(user_content.search_keywords,
                function (res) {
                    data.userArray = res;
                },
                function (err) {
                    console.log(err);
                })
        },
        //设置用户账号是否禁用
        setavailable : function(index){
            console.log("点击了账号禁用");
            this.edit_username = this.userArray[index].username;
            this.available = this.userArray[index].available;
            _other_service.modifyUserStatus(
                user_content.edit_username,
                user_content.available,
                function(res) {
                    alert("修改用户状态成功");
                },
                function(err) {
                    alert("修改用户状态失败");
                }
            )
        },
        deleteUserAccount: function (index){
            this.edit_username = this.userArray[index].username;
            _other_service.deleteUserAccount(
                user_content.edit_username,
                function(res) {
                    alert("用户删除成功");
                },
                function(err) {
                    alert("用户删除失败");
                }
            )
        },
        resetSearchInfo : function(){
            this.search_keywords = "请输入用户名";
        }
    },
    //初始化vue对象，渲染数据
    created: function () {
        _other_service.getalluser(user_content.pagesize, user_content.pageid,
            function (res) {
                user_content.data.userArray = res.data;
            },
            function (res) {
                console.log("渲染数据错误")
            }
        );
    },
});
